package com.mohe.zhihui.utils;

/**
 * 计算分数
 * @author wlc
 *
 */
public class WeightUtil {
	
	/**
	 * 根据传入的参数计算对应的指标所对应的分数
	 * @param x x值
	 * @param a a值
	 * @param b b值
	 * @param c c值
	 * @param type 类型（1递减2递增3三角4是否5等级6累加）
	 * @return
	 */
	public static double getWeight(double x,double a,double b,double c,int type,double weight){
		double result=0.0;
		switch (type) {
		case 1:
			result= Decrease(x,a,b,c,weight);
			break;
		case 2:
			result = Progressive(x,a,b,c,weight);
			break;
		case 3:
			result =Triangle(x,a,b,c,weight);
			break;
		default:
			break;
		}
		return result;
	}
	
	/**
	 * 递减
	 * @param x
	 * @param a
	 * @param b
	 * @param c
	 * @param weight
	 * @return
	 */
	private static double Decrease(double x,double a,double b,double c,double weight){
		if(x<=a || x>=c){
			return 0;
		}else{
			return (a-x)/(b-a)*weight;
		}
	}
	
	/**
	 * 递增
	 * @param x
	 * @param a
	 * @param b
	 * @param c
	 * @param weight
	 * @return
	 */
	private static double Progressive(double x,double a,double b,double c,double weight){
		if(x<=a){
			return 0;
		}else if(x>=b){
			return weight;
		}else{
			return (x-a)/(b-a)*weight;
		}
	}
	
	/**
	 * 三角
	 * @param x
	 * @param a
	 * @param b
	 * @param c
	 * @param weight
	 * @return
	 */
	private static double Triangle(double x,double a,double b,double c,double weight){
		if(x<=a || x>=c){
			return 0;
		}else if(x>a && x<=b){
			return (x-a)/(b-a)*weight;
		}else{
			return (c-x)/(c-b)*weight;
		}
	}
	
	/**
	 * 是否
	 * @param x
	 * @param a
	 * @param b
	 * @param c
	 * @param weight
	 * @return
	 */
//	private static double isBoolean(double x,double a,double b,double c,double weight){
//	}
	

}